package com.dd.keel.core.common.utils;

/**
 * Stop watch util
 * 1 milli second = 1000,000 nano seconds
 * @author Kevin.XU
 *
 */

public class StopWatch {

	private long startTime = 0L;
	private long endTime = 0L;
	
	final static public int NANO_TIME_UNIT = 1;
	final static public int MILLI_TIME_UNIT = 2;
	
	private int timeUnit = 0;
	
	public StopWatch()
	{
		timeUnit = MILLI_TIME_UNIT;
	}
	
	public StopWatch(int newTimeUnit)
	{
		timeUnit = newTimeUnit;
	}
	
	public void start()
	{
		if(timeUnit==NANO_TIME_UNIT)
			startTime = System.nanoTime();
		if(timeUnit==MILLI_TIME_UNIT)
			startTime = System.currentTimeMillis();
	}
	
	public void restart()
	{
		start();
	}
	
	public void stop()
	{
		if(timeUnit==NANO_TIME_UNIT)
			endTime = System.nanoTime();
		if(timeUnit==MILLI_TIME_UNIT)
			endTime = System.currentTimeMillis();
	}
	
	public long cost()
	{
		return (endTime-startTime);
	}
	
}

